achievement_send_challenge


语法:

achievement_send_challenge(playerid, challengeid, score, type, message)

参数 描述
playerid The unique ID of the player to challenge.
challengeid The unique challenge ID (as found on the provider dashboard).
score The score to beat.
type the type of challenge to be issued - one of two constants given below.
message The message to attach to the challenge.


返回:

N/A(无返回值)


描述

This function will send a challenge across the network to the chosen player. You can get the playerid using the achievement_load_friends or the achievement_load_leaderboard functions and you must also supply the challengeid which is the unique value given the challenge when you created it on your iTunes Connect or Google Play dashboard. You must also supply a score, and a short text message as well as set the challenge type. This can be one of the following constants:

  • achievement_type_score_challenge - 基于分数值的挑战。
  • achievement_type_achievement_challenge - 基于成就的挑战。

This function will trigger a callback Social Asynchronous Event for the player that is to receive the challenge, and in this event you will have a ds_map referenced in the variable async_load. The id key of this ds_map is used to identify the correct callback (there can be more than one trigger function for any given asynchronous event), and will be paired with the constant achievement_challenge_received as well as a number of other key/value pairs for each player. The exact contents of the map are shown below:

NOTE: that the user can also receive toast notifications for challenges received, but this will depend on the values you have chosen using the function achievement_show_challenge_notifications.
  1. "id" - For this function it should be achievement_leaderboard_info

  2. "playerid" - The player ID for the challenge.

  3. "issuerid" - The issuer ID for the challenge.

  4. "state" - The state of the challenge, which will have a value of 0 - 3 (as a string) for invalid, pending, completed or declined.

  5. "message" - The text message for challenge.

  6. "completeddate" - The completion date for challenge.

  7. "issueddate" - The issue date for challenge.

  8. "type" - The type of challenge given. 可以是两个常量之一:
    • achievement_type_score_challenge - 基于分数值的挑战。
    • achievement_type_achievement_challenge - 基于成就的挑战。
  9. "identifier" - The identifying string for the challenge, as set on the provider dashboard

  10. "score" - The score tied in with the challenge (if applicable).


Extended 举例:

To send a challenge over the network you would have this code:

achievement_send_challenge(global.playerid[0], global.challengeid[0], score, achievement_type_score_challenge, "Beat that sucker!");

This request will then trigger the Social Event in your game for the player that the challenge was directed at, and this can be dealt with in the following way:

var ident = ds_map_find_value(async_load, "id");
if ident == achievement_challenge_received
   {
   player_id = ds_map_find_value(async_load, "playerid");
   issuer_id = ds_map_find_value(async_load, "issuerid");
   state = ds_map_find_value(async_load, "state");
   message = ds_map_find_value(async_load, "message");
   date_completed = ds_map_find_value(async_load, "completeddate");
   date_issued = ds_map_find_value(async_load, "issueddate");
   ach_type = ds_map_find_value(async_load, "type");
   ach_ident = ds_map_find_value(async_load, "identifier");
   ach_score = ds_map_find_value(async_load, "score");
   }

The above code checks the returned ds_map in the Social Asynchronous Event and if its "id" matches the constant being checked, it then extracts the relevant values for each of the keys in the map and stores them in variables for future use.